#include "databasehelper.h"
#include <QSqlDatabase>
#include <QSqlError>
#include <QSqlQuery>
#include <QDateTime>
#include <QDebug>
#include <QLinkedList>
#include <QString>
#include <QDateTime>
#include <QThread>
#include "excelgeneration.h"

#define USE_LOCALHOST_DATABASE
const QString Databasehelper::LOG = "DatabaseHelper";

// Database Version
const int Databasehelper::DATABASE_VERSION = 1;

#if defined USE_LOCALHOST_DATABASE
    // Database Name
    const QString Databasehelper::DATABASE_NAME = "sunshinenailsva_accounting";
    const QString Databasehelper::USER = "nailsaccounting";
    const QString Databasehelper::PASSWORD = "erujybuby";
    const QString Databasehelper::HOST = "localhost";
#else
    // Database Name
    const QString Databasehelper::DATABASE_NAME = "sunshinenailsva_accounting";
    const QString Databasehelper::USER = "nailsaccounting";
    const QString Databasehelper::PASSWORD = "erujybuby";
    const QString Databasehelper::HOST = "sunshinenailsva.com";
#endif



// Table Names
const QString Databasehelper::TABLE_EMPLOYEES = "employees";
const QString Databasehelper::TABLE_EMPLOYEE_INCOMES = "employee_incomes";
const QString Databasehelper::TABLE_SALON_INCOMES = "salon_incomes";
const QString Databasehelper::TABLE_EXPEND_SALARY = "expend_salary";
const QString Databasehelper::TABLE_EXPENSE_ITEMS = "expense_items";


// Common column names
const QString Databasehelper::FIELD_ID = "id";
const QString Databasehelper::FIELD_CREATED_AT = "created_at";
const QString Databasehelper::FIELD_MODIFIED_AT = "modified_at";

// EMPLOYEES Table - column names
const QString Databasehelper::FIELD_EMPLOYEES_NAME = "name";
const QString Databasehelper::FIELD_EMPLOYEES_PHONE = "phone";
const QString Databasehelper::FIELD_EMPLOYEES_SALARY_RATE = "salary_rate";
const QString Databasehelper::FIELD_EMPLOYEES_CASH_RATE = "cash_rate";
const QString Databasehelper::FIELD_EMPLOYEES_WORKING_STATUS = "working";
const QString Databasehelper::FIELD_EMPLOYEES_PAID_AT = "paid_at";

// EMPLOYEE_INCOMES Table - column names
const QString Databasehelper::FIELD_EMPLOYEE_INCOMES_EMPLOYEE_ID = "employee_id";
const QString Databasehelper::FIELD_EMPLOYEE_INCOMES_SALARY = "salary";
const QString Databasehelper::FIELD_EMPLOYEE_INCOMES_TIP = "tip";

// SALON_INCOMES Table - column names
const QString Databasehelper::FIELD_SALON_INCOMES_CASH = "cash";
const QString Databasehelper::FIELD_SALON_INCOMES_CREDIT =  "credit";
const QString Databasehelper::FIELD_SALON_INCOMES_TOTAL = "total";
const QString Databasehelper::FIELD_SALON_INCOMES_GIFT_OUT = "gift_out";
const QString Databasehelper::FIELD_SALON_INCOMES_GIFT_IN = "gift_in";

// EXPEND_SALARY table - column names
const QString Databasehelper::FIELD_EXPEND_SALARY_EMPLOYEE_ID = "employee_id";
const QString Databasehelper::FIELD_EXPEND_SALARY_SALARY_RATE = "salary_rate";
const QString Databasehelper::FIELD_EXPEND_SALARY_CASH_RATE = "cash_rate";
const QString Databasehelper::FIELD_EXPEND_SALARY_CASH = "cash";
const QString Databasehelper::FIELD_EXPEND_SALARY_CHECK = "check";
const QString Databasehelper::FIELD_EXPEND_SALARY_TIP = "tip";
const QString Databasehelper::FIELD_EXPEND_SALARY_START_AT = "start_at";
const QString Databasehelper::FIELD_EXPEND_SALARY_END_AT = "end_at";


// EXPEND_ITEMS table - column names
const QString Databasehelper::FIELD_EXPEND_ITEMS_NAME = "name";
const QString Databasehelper::FIELD_EXPEND_ITEMS_ICON = "icon";
const QString Databasehelper::FIELD_EXPEND_ITEMS_COLOR = "color";


Databasehelper::Databasehelper()
{
}

void Databasehelper::closeConnection()
{
    db.close();
    QSqlDatabase::removeDatabase(Databasehelper::DATABASE_NAME);
}

bool Databasehelper::openConnection()
{
    QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
    db.setDatabaseName(Databasehelper::DATABASE_NAME);
    db.setUserName(Databasehelper::USER);
    db.setPassword(Databasehelper::PASSWORD);
    db.setHostName(Databasehelper::HOST);
    return db.open();
}

int Databasehelper::createEmployee(Employee *employee)
{
    if (db.isOpen())
    {
        QSqlQuery query(this->db);
        QDateTime timestamp = QDateTime::currentDateTime();

        //qDebug()<< timestamp.toTime_t();
        QString query_str;
        query_str = "INSERT INTO " + Databasehelper::TABLE_EMPLOYEES +
                +"(" + Databasehelper::FIELD_EMPLOYEES_NAME  +
                +","+ Databasehelper::FIELD_EMPLOYEES_PHONE +
                +","+ Databasehelper::FIELD_EMPLOYEES_SALARY_RATE +
                +","+ Databasehelper::FIELD_EMPLOYEES_CASH_RATE +
                +","+ Databasehelper::FIELD_EMPLOYEES_WORKING_STATUS +
                +","+ Databasehelper::FIELD_CREATED_AT +
                +","+ Databasehelper::FIELD_MODIFIED_AT +
                +","+ Databasehelper::FIELD_EMPLOYEES_PAID_AT +
                +") VALUES " +
                +"('"   + employee->getName() +"'"+
                +",'"   + employee->getPhone()+"'"+
                +","    + QString::number(employee->getSalaryRate())+
                +","    + QString::number(employee->getCashRate())+
                +","    + QString::number(employee->getWorkingStatus() ? 1:0)+
                +","    + QString::number(timestamp.toTime_t())+
                +",(select max("+ Databasehelper::FIELD_EMPLOYEES_PAID_AT +") from "+ Databasehelper::TABLE_EMPLOYEES +"))";
        qDebug()<< query_str;
        query.prepare(query_str);
        if( !query.exec() ){
            qDebug() << query.lastError();
            return -1;
        }
        else{

            qDebug( "Inserted new Employee!" );
            return query.lastInsertId().toInt();
        }
    }else{
        return -1;
    }
}

bool Databasehelper::updateEmployee(Employee *employee)
{
    QSqlQuery query;
    QDate modifiedTime = QDate::currentDate();

    QString query_str;
    query_str.clear();

    query_str  = "UPDATE "  + Databasehelper::TABLE_EMPLOYEES        + " SET "
               +      Databasehelper::FIELD_EMPLOYEES_NAME           + "='"         + employee->getName()       + "'"+
               + "," +Databasehelper::FIELD_EMPLOYEES_PHONE          + "='"         + employee->getPhone()      + "'"+
               + "," +Databasehelper::FIELD_EMPLOYEES_SALARY_RATE    + "="          + QString::number(employee->getSalaryRate()) +
               + "," +Databasehelper::FIELD_EMPLOYEES_CASH_RATE      + "="          + QString::number(employee->getCashRate())   +
               + "," +Databasehelper::FIELD_EMPLOYEES_WORKING_STATUS + "="          + QString::number(employee->getWorkingStatus())    +
               + "," +Databasehelper::FIELD_MODIFIED_AT  + "='"       + modifiedTime.toString("yyyy-MM-dd") + "'"
               + " where name='"+ employee->getName()+"'";

    qDebug()<< query_str;
    query.prepare(query_str);
    if( !query.exec() ){
        qDebug() << query.lastError();
        return false;
    }
    else{
        qDebug( "Updated Employee!" );
        return true;
    }
}

QLinkedList<Employee*>* Databasehelper::selectEmployee(QString condition)
{
    QSqlQuery query;
    QString query_str;
    QLinkedList<Employee*> *EmployeeList = new QLinkedList<Employee*>();
    query_str.clear();
    query_str = "SELECT * FROM " + Databasehelper::TABLE_EMPLOYEES;
    query_str += condition;
    query_str += " ORDER BY "+ Databasehelper::FIELD_EMPLOYEES_NAME + " ASC";

    query.prepare(query_str);
    if( !query.exec() ){
        qDebug() << query.lastError();
        return NULL;
    }
    else{
        while (query.next()){
            int employeeId = query.value(Databasehelper::FIELD_ID).toInt();
            QString employeeName = query.value(Databasehelper::FIELD_EMPLOYEES_NAME).toString();
            QString employeePhone = query.value(Databasehelper::FIELD_EMPLOYEES_PHONE).toString();
            double employeeSalaryRate = query.value(Databasehelper::FIELD_EMPLOYEES_SALARY_RATE).toDouble();
            double employeeCashRate = query.value(Databasehelper::FIELD_EMPLOYEES_CASH_RATE).toDouble();
            int employeeWorking = query.value(Databasehelper::FIELD_EMPLOYEES_WORKING_STATUS).toInt();
            QDateTime employeeCreatedDate = query.value(Databasehelper::FIELD_CREATED_AT).toDateTime();
            QDateTime employeeModifiedDate = query.value(Databasehelper::FIELD_MODIFIED_AT).toDateTime();
            QDateTime employeePaidDate = query.value(Databasehelper::FIELD_EMPLOYEES_PAID_AT).toDateTime();
            Employee *queryEmployee = new Employee();
            queryEmployee->setId(employeeId);
            queryEmployee->setCashRate(employeeCashRate);
            queryEmployee->setName(employeeName);
            queryEmployee->setPhone(employeePhone);
            queryEmployee->setSalaryRate(employeeSalaryRate);
            queryEmployee->setWorkingStatus(employeeWorking);
            queryEmployee->setCreatedAt(employeeCreatedDate);
            queryEmployee->setModifiedAt(employeeModifiedDate);
            queryEmployee->setPaidAt(employeePaidDate);

            EmployeeList->append(queryEmployee);

        }
        return EmployeeList;
    }
}

int Databasehelper::createEmployeeIncomes(EmployeeIncome *empl_incomes)
{
    return 0;
}

bool Databasehelper::updateEmployeeIncomes(QStandardItemModel* model, QProgressDialog *progressDialog){

    QModelIndex index;
    QSqlQuery *sqlQuery = new QSqlQuery;
    int row;
    QString name, dateModel_str;
    int id;
    float salary;
    float tip;

    qDebug() << "row:" << model->rowCount();
    QDate dateModel;
    for (row = 0; row < model->rowCount(); row++)
    {
        progressDialog->setValue(row);
        index = model->index(row,EmployeeIncome::ID_COL);
        id = model->data(index).toInt();
        index = model->index(row,EmployeeIncome::NAME_COL);
        name = model->data(index).toString();

        index = model->index(row,EmployeeIncome::DATE_COL);
        dateModel_str = model->data(index).toString();
        dateModel = QDate::fromString(dateModel_str,"MM-dd-yyyy");
        QDate created_at(dateModel);

        index = model->index(row,EmployeeIncome::SALARY_COL);
        salary = model->data(index).toDouble();

        index = model->index(row,EmployeeIncome::TIP_COL);
        tip = model->data(index).toDouble();

        QDate modified_at = QDate::currentDate();
        if (id == 0) continue;

        QString query_str;
        query_str = "INSERT INTO " + Databasehelper::TABLE_EMPLOYEE_INCOMES
                +" ("+Databasehelper::FIELD_EMPLOYEE_INCOMES_EMPLOYEE_ID
                +", " + Databasehelper::FIELD_EMPLOYEE_INCOMES_SALARY
                +", "+Databasehelper::FIELD_CREATED_AT
                +", "+ Databasehelper::FIELD_MODIFIED_AT
                +", "+Databasehelper::FIELD_EMPLOYEE_INCOMES_TIP+") values("
                + QString::number(id) + "," + QString::number(salary,'f',2) +",'" + created_at.toString("yyyy-MM-dd")+ "','" + modified_at.toString("yyyy-MM-dd") +
                "'," + QString::number(tip,'f',2) +
                ")";
        qDebug()<< query_str;
        if (!sqlQuery->exec(query_str)){
            query_str = "Update "+Databasehelper::TABLE_EMPLOYEE_INCOMES
                    +" set "+Databasehelper::FIELD_EMPLOYEE_INCOMES_SALARY+"="+QString::number(salary,'f',2)
                    +", "+Databasehelper::FIELD_EMPLOYEE_INCOMES_TIP+"=" + QString::number(tip,'f',2)

                    +", "+Databasehelper::FIELD_MODIFIED_AT+"="
                    +"'" + modified_at.toString("yyyy-MM-dd") + "'"
                    + " where "+Databasehelper::FIELD_EMPLOYEE_INCOMES_EMPLOYEE_ID +"="
                    +QString::number(id)+" AND "+ Databasehelper::FIELD_CREATED_AT +"="
                    +"'" + created_at.toString("yyyy-MM-dd") + "'";
            qDebug()<< query_str;
            sqlQuery->exec(query_str);

        }
        QThread::msleep(10);

    }
    return true;
}

QLinkedList<EmployeeIncome *> *Databasehelper::selectEmployeeIncomes(const QDate dateIncome)
{
    QSqlQuery query;
    QString query_str;
    QLinkedList<EmployeeIncome*> *employeeIncomesList = new QLinkedList<EmployeeIncome*>();
    query_str.clear();
    bool new_income = false;
    query_str = "SELECT *"
                        " FROM employees_incomes_view"
                        " WHERE created_at= '"+dateIncome.toString("yyyy-MM-dd")+ "'"
                        " order by name";

    qDebug() << query_str;
    query.prepare(query_str);
    if( !query.exec() ){
        qDebug() << query.lastError();
        return NULL;
    }else{

    }
    if (query.size() == 0){
        new_income = true;
        query_str = "SELECT id as employee_id, name "
                            " FROM employees"
                            " WHERE working=1"
                            " order by name";
        query.prepare(query_str);
        qDebug() << query_str;

        if( !query.exec() ){
            qDebug() << query.lastError();
            return NULL;
        }else{

        }

    }
    int employeeIncomesId = 0;
    double tip = 0;
    double salary = 0;

    while (query.next()){
        if (!new_income)
        {
            employeeIncomesId = query.value(Databasehelper::FIELD_ID).toInt();
            tip = query.value(Databasehelper::FIELD_EMPLOYEE_INCOMES_TIP).toInt();
            salary = query.value(Databasehelper::FIELD_EMPLOYEE_INCOMES_SALARY).toInt();
        }
        int employeeId = query.value(Databasehelper::FIELD_EMPLOYEE_INCOMES_EMPLOYEE_ID).toInt();
        QString name = query.value(Databasehelper::FIELD_EMPLOYEES_NAME).toString();

        EmployeeIncome *queryEmployeeIncomes = new EmployeeIncome();

        queryEmployeeIncomes->setId(employeeIncomesId);
        queryEmployeeIncomes->setSalary(salary);
        queryEmployeeIncomes->setTip(tip);

        queryEmployeeIncomes->setEmployeeId(employeeId);
        queryEmployeeIncomes->setName(name);
        employeeIncomesList->append(queryEmployeeIncomes);

    }
    return employeeIncomesList;

}

QLinkedList<EmployeeIncome *> *Databasehelper::selectEmployeeIncomes(QString condition)
{
    return NULL;
}

bool Databasehelper::updateSalonIncomes(QStandardItemModel *model, QString note, QProgressDialog *progressDialog)
{
    QModelIndex index;
    QSqlQuery *sqlQuery = new QSqlQuery;
    int row;
    QString dateModel_str;
    int id;
    float cash, credit, total, gift_card_in, gift_card_out;


    QDate dateModel;
    for (row = 0; row < model->rowCount(); row++)
    {
        progressDialog->setValue(row);
        index = model->index(row,SalonIncome::ID_COL);
        id = model->data(index).toInt();

        index = model->index(row,SalonIncome::CASH_COL);
        cash = model->data(index).toDouble();

        index = model->index(row,SalonIncome::CREDIT_COL);
        credit = model->data(index).toDouble();
        index = model->index(row,SalonIncome::GIFT_CARD_IN);
        gift_card_in = model->data(index).toDouble();
        index = model->index(row,SalonIncome::GIFT_CARD_OUT);
        gift_card_out = model->data(index).toDouble();


        index = model->index(row,SalonIncome::TOTAL_COL);
        total = model->data(index).toDouble();

        index = model->index(row,SalonIncome::CREATEDDATE_COL);
        dateModel_str = model->data(index).toString();

        dateModel = QDate::fromString(dateModel_str,"MM-dd-yyyy");
        QDate modifiedDate = QDate::currentDate();
        QString query_str;
        query_str = "INSERT INTO salon_incomes (cash,credit,total, gift_out, gift_in, created_at, modified_at, note) values("
                + QString::number(cash,'f',2) + "," + QString::number(credit,'f',2) + "," + QString::number(total,'f',2) +
                + "," + QString::number(gift_card_out,'f',2) + "," + QString::number(gift_card_in,'f',2) + ",'" + dateModel.toString("yyyy-MM-dd") + "','" + modifiedDate.toString("yyyy-MM-dd") + "','" + note +"')";
        qDebug()<< query_str;
        if (!sqlQuery->exec(query_str)){
            query_str = "Update salon_incomes set cash="+ QString::number(cash,'f',2)
                    +",credit="+ QString::number(credit,'f',2)
                    +",total="+ QString::number(total,'f',2)
                    +",gift_card_in="+ QString::number(gift_card_in,'f',2)
                    +",gift_card_out="+ QString::number(gift_card_out,'f',2)
                    +",modified_at='"+ modifiedDate.toString("yyyy-MM-dd") +"'"
                    +",note='"+ note +"'"
                    + " where created_at='" + dateModel.toString("yyyy-MM-dd") + "'";
            qDebug()<< query_str;
            sqlQuery->exec(query_str);

        }
        QThread::msleep(10);

    }
    return true;
}

QDate Databasehelper::getLastPaidDate()
{
    QDate lastDate = QDate::currentDate();
    QSqlQuery query;
    QString query_str;
    query_str = "select max(paid_at) as paid_at from employees";

    qDebug() << query_str;
    query.prepare(query_str);
    if( !query.exec() ){
        qDebug() << query.lastError();
    }
    else{
        qDebug() << "row= "<<query.size();

        if (query.next()){
            lastDate = query.value(Databasehelper::FIELD_EMPLOYEES_PAID_AT).toDate().addDays(14);
        }

    }
    return lastDate;
}

bool Databasehelper::updatePayroll(QStandardItemModel *model, QProgressDialog *progressDialog){
    QModelIndex index;
    QSqlQuery *sqlQuery = new QSqlQuery;
    int row;
    QString name;
    int id, employee_id;
    double salary_rate, cash_rate;
    float cash, check, tip;
    QDate start_at, end_at, created_at, modified_at;
    QDate dateConvert;

    bool createdSalarySumary = false;
    for (row = 0; row < model->rowCount(); row++)
    {
        progressDialog->setValue(row);
        index = model->index(row,SalaryExpend::ID_COL);
        id = model->data(index).toInt();

        index = model->index(row,SalaryExpend::EMPLOYEE_ID_COL);
        employee_id = model->data(index).toInt();

        index = model->index(row,SalaryExpend::EMPLOYEE_NAME_COL);
        name = model->data(index).toString();

        index = model->index(row,SalaryExpend::SALARY_RATE_COL);

        salary_rate = model->data(index).toDouble();

        index = model->index(row, SalaryExpend::CASH_RATE_COL);
        cash_rate = model->data(index).toDouble();

        index = model->index(row,SalaryExpend::FROM_AT_COL);
        qDebug() << model->data(index).toString();
        start_at = dateConvert.fromString(model->data(index).toString(), "MM-dd-yyyy");

        index = model->index(row,SalaryExpend::TO_AT_COL);
        end_at = dateConvert.fromString(model->data(index).toString(), "MM-dd-yyyy");

        index = model->index(row,SalaryExpend::CREATED_AT_COL);
        created_at = dateConvert.fromString(model->data(index).toString(), "MM-dd-yyyy");
        modified_at = QDate::currentDate();

        index = model->index(row,SalaryExpend::CASH_COL);
        cash = model->data(index).toDouble();

        index = model->index(row,SalaryExpend::CHECK_COL);
        check = model->data(index).toDouble();

        index = model->index(row,SalaryExpend::TIP_COL);
        tip = model->data(index).toDouble();

        if (!createdSalarySumary){ //only create report 1 time.
            ExcelGeneration::ReportSalarySumary(start_at, end_at);
            createdSalarySumary = true;
        }
        ExcelGeneration::ReportWorkerIncome(employee_id, start_at, end_at);

        QString query_str;
        query_str = "INSERT INTO `expend_salary`(`employee_id`,"
                "`employee_name`, `salary_rate`, `cash_rate`, `cash`,"
                "`check`, `tip`, `start_at`, `end_at`, `created_at`, `modified_at`) VALUES ("
                + QString::number(employee_id)
                + ",'" + name
                + "'," + QString::number(salary_rate)
                + "," + QString::number(cash_rate) + ","
                + QString::number(cash,'f',2) + ","
                + QString::number(check,'f',2) + ","
                + QString::number(tip,'f',2)
                + ",'" + start_at.toString("yyyy-MM-dd") +"'"
                + ",'" + end_at.toString("yyyy-MM-dd") + "'"
                + ",'" + created_at.toString("yyyy-MM-dd") + "'"
                + ",'" + modified_at.toString("yyyy-MM-dd")
                + "')";
        if (sqlQuery->exec(query_str)){

        }
        QThread::msleep(10);

    }
    if (model->rowCount() > 0)
    {
        sqlQuery->exec( "Update employees set paid_at = '" + end_at.toString("yyyy-MM-dd") + "'");
    }
    delete sqlQuery;
    return true;
}

int Databasehelper::updateExpenseItems(ExpenseItems *expense_items)
{
    QSqlQuery query(this->db);
    QDateTime timestamp = QDateTime::currentDateTime();
    int id = 0;
    QString query_str;
    query_str = "INSERT INTO " + Databasehelper::TABLE_EXPENSE_ITEMS +
            +"(" + Databasehelper::FIELD_EXPEND_ITEMS_NAME  +
            +","+ Databasehelper::FIELD_EXPEND_ITEMS_ICON +
            +","+ Databasehelper::FIELD_EXPEND_ITEMS_COLOR +
            +","+ Databasehelper::FIELD_CREATED_AT +
            +") VALUES " +
            +"('"   + expense_items->getName() +"'"+
            +",'"    + expense_items->getIcon()+
            +"','"    + expense_items->getColor()+
            +"','"   + timestamp.toString("yyyy-MM-dd")
            +"')";
    qDebug()<< query_str;
    query.prepare(query_str);
    if( id = query.exec() ){
        qDebug( "Inserted new expense item!" );

    }
    else{
        qDebug() << query.lastError();
        query_str  = "UPDATE "  + Databasehelper::TABLE_EXPENSE_ITEMS    + " SET "
                   +      Databasehelper::FIELD_EXPEND_ITEMS_NAME        + "='"
                   +      expense_items->getName()      + "'"+
                   + "," +Databasehelper::FIELD_EXPEND_ITEMS_COLOR       + "='"
                   + expense_items->getColor()           +
                   + "'," +Databasehelper::FIELD_EXPEND_ITEMS_ICON        + "='"
                   + expense_items->getIcon()           +
                   + "'," +Databasehelper::FIELD_MODIFIED_AT              + "='"
                   + timestamp.toString("yyyy-MM-dd") + "'"
                   + " where id="+ expense_items->getId();
        qDebug()<< query_str;

        query.prepare(query_str);
        id = query.exec();
    }

    return id;

}

QLinkedList<ExpenseItems *> *Databasehelper::selectExpenseItems()
{
    QSqlQuery query;
    QString query_str;
    QLinkedList<ExpenseItems*> *expenseItemList = new QLinkedList<ExpenseItems*>();
    query_str.clear();
    query_str = "SELECT *"
                        " FROM " + Databasehelper::TABLE_EXPENSE_ITEMS;

    qDebug() << query_str;
    query.prepare(query_str);
    if( !query.exec() ){
        qDebug() << query.lastError();
        return NULL;
    }else{

    }
    int id = 0;
    QString color;
    QString icon;
    while (query.next()){

        id = query.value(Databasehelper::FIELD_ID).toInt();
        color = query.value(Databasehelper::FIELD_EXPEND_ITEMS_COLOR).toString();
        icon = query.value(Databasehelper::FIELD_EXPEND_ITEMS_ICON).toString();
        ExpenseItems *queryExpenseItem = new ExpenseItems();

        queryExpenseItem->setId(id);
        queryExpenseItem->setColor(color);
        queryExpenseItem->setIcon(icon);

        expenseItemList->append(queryExpenseItem);

    }
    return expenseItemList;
}



